<?php

class Khoa_thisController extends BaseController {

    /**
     * Khoa_thi Repository
     *
     * @var Khoa_thi
     */
    protected $khoa_thi;

    public function __construct(Khoa_thi $khoa_thi) {
        $this->khoa_thi = $khoa_thi;
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index() {
        $khoa_this = $this->khoa_thi->all();
        return View::make('khoa_this.index', compact('khoa_this'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create() {
        $hoi_dong_thi = Hoi_dong_thi::all();
        return View::make('khoa_this.create')->with('hoi_dong_thi', $hoi_dong_thi);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store() {
        $input = Input::all();
        $validation = Validator::make($input, Khoa_thi::$rules);

        if ($validation->passes()) {
            $this->khoa_thi->create($input);

            return Redirect::route('courses.index');
        }

        return Redirect::route('courses.create')
                        ->withInput()
                        ->withErrors($validation)
                        ->with('message', 'There were validation errors.');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id) {
        $khoa_thi = $this->khoa_thi->findOrFail($id);

        return View::make('khoa_this.show', compact('khoa_thi'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id) {
        $khoa_thi = $this->khoa_thi->find($id);
        $hoi_dong_thi = Hoi_dong_thi::all();
        if (is_null($khoa_thi)) {
            return Redirect::route('courses.index');
        }

        return View::make('khoa_this.edit', compact('khoa_thi'))->with('hoi_dong_thi', $hoi_dong_thi);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id) {
        $input = array_except(Input::all(), '_method');
 
        $khoa_thi = $this->khoa_thi->find($id);
        if ($khoa_thi->update($input)) {
            return Redirect::route('courses.show', $id);
        }

        return Redirect::route('courses.edit', $id)
                        ->withInput()
                        ->withErrors($validation)
                        ->with('message', 'There were validation errors.');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id) {
        $this->khoa_thi->find($id)->delete();
        return 1;
        // return Redirect::route('courses.index');
    }

}
